/*
 * @Author: yangni 920556271@qq.com
 * @Date: 2023-08-28 15:10:58
 * @LastEditors: yangni 920556271@qq.com
 * @LastEditTime: 2024-03-27 10:39:00
 * @FilePath: /yt-devops/lib/pages/devices/device_tab/device_detail/pcs_detail/pcs_detail_view.dart
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/model/device_model.dart';
import 'package:yt_devops/pages/devices/device_tab/utils/device_util.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/utils/enums.dart';
import '../../components/detail_grid_widget.dart';
import 'pcs_detail_controller.dart';

class PcsDetailPage extends GetView<PcsDetailController> {
  final DeviceModel? deviceModel;
  const PcsDetailPage({Key? key, this.deviceModel}) : super(key: key);

  @override
  PcsDetailController get controller =>
      Get.put<PcsDetailController>(PcsDetailController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget.defaultAppBar(deviceModel?.name ?? ''),
      body: GetBuilder<PcsDetailController>(
        initState: (state) {
          controller.deviceModel = deviceModel;
          controller.initData();
        },
        dispose: (state) => Get.delete<PcsDetailController>(),
        builder: (controller) => SafeArea(
          child: StreamBuilder(
            stream: controller.dataStream,
            builder: (context, snapshot) => ListView(
              padding: EdgeInsets.only(bottom: 10.h),
              children: [
                DeviceUtil.blockContainer(
                  DetailGridWidget(
                    title: ResKey.runningState.tr,
                    items: controller.model.runItems,
                    dataSource: snapshot.data,
                    isSingleRow: false,
                    isLightTtext:
                        controller.connectStatus != ConnectStatusType.on,
                  ),
                ),
                DeviceUtil.blockContainer(
                  DetailGridWidget(
                    title: ResKey.communicationSideInfo.tr,
                    items: controller.model.exchargeItems,
                    dataSource: snapshot.data,
                    isSingleRow: false,
                    isLightTtext:
                        controller.connectStatus != ConnectStatusType.on,
                  ),
                ),
                DeviceUtil.blockContainer(
                  DetailGridWidget(
                    title: ResKey.dCSideInfo.tr,
                    items: controller.model.directCurrentItems,
                    dataSource: snapshot.data,
                    isLightTtext:
                        controller.connectStatus != ConnectStatusType.on,
                  ),
                ),
                DeviceUtil.blockContainer(
                  DetailGridWidget(
                    title: ResKey.temperatureInfo.tr,
                    items: controller.model.tempItems,
                    dataSource: snapshot.data,
                    isLightTtext:
                        controller.connectStatus != ConnectStatusType.on,
                  ),
                ),
                DeviceUtil.blockContainer(
                  DetailGridWidget(
                    title: ResKey.versionInfo.tr,
                    items: controller.model.versionItems,
                    dataSource: snapshot.data,
                    isLightTtext:
                        controller.connectStatus != ConnectStatusType.on,
                  ),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
